Sample Code - SQLQueryString Property

This sample code shows the use of the SQLQueryString Property of the Report Object. Modify the following sample code to fit your needs.

Option Explicit

Dim app1 As CRPEAuto.Application
Dim rpt1 As CRPEAuto.Report

Private Sub Form_Load()
    Set app1 = CreateObject("Crystal.CRPE.Application)
    Set rpt1 = app1.OpenReport("c:\reports\myreport.rpt")
End Sub

Private Sub Command1_Click()
    Dim sqlString As String

    ' Change log on info for the report
    rpt1.Database.Tables(1).SetLogOnInfo "CRSS", _
        "pubs", "user1", "password"
    rpt1.Database.Tables(2).SetLogOnInfo "CRSS", _
        "pubs", "user1", "password"

    ' Change the SQL query of the report
    sqlString = "SELECT publishers.pub_name, titles.title, _
        titles.ytd_sales" & Chr$(13)
    sqlString = sqlString & "FROM pubs.dbo.publishers publishers, _
        pubs.dbo.titles titles" & Chr$(13)
    sqlString = sqlString & "WHERE publishers.pub_id = _
        titles.pub_id" & Chr$(13)
    sqlString = sqlString & "AND publishers.pub_name = _
        'Binnet & Hardley'" & Chr$(13)
    sqlString = sqlString & "ORDER BY publishers.pub_name ASC"

    rpt1.SQLQueryString = sqlString

    ' Preview the report
    rpt1.Preview
End Sub


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com